'use strict';
let Response = require('../../../model/Response');
let RestifyProxy = require('../../../util/RestifyProxy');
let CustomPageBean = require('../../../model/CustomPageBean');
let projectService = require('../../../service/operate/projectService');
let logger = require('../../../util/LoggerUtil').logger('projectController.js');

/**
 * 项目管理——页面
 */
module.exports.projectPage = function () {
    let response = new Response();
    response.render('back/operate/project/project');//html路径
    this.resolve(response);
};

/**
 * 项目管理——列表数据
 */
module.exports.projectList = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await projectService.projectList(this, params);
        let pageBean = new CustomPageBean(result);
        response.send(pageBean);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/**
 * 项目管理-创建页面
 */
module.exports.projectCreatePage = function () {
    let response = new Response();
    response.render('back/operate/project/project_create');
    this.resolve(response);
};
/*项目管理-创建页面-保存按钮*/
module.exports.projectCreateSave = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await projectService.projectCreateSave(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/**
 * 项目管理-详情页面
 */
module.exports.projectDetailPage = function () {
    let response = new Response();
    response.render('back/operate/project/project_detail');
    this.resolve(response);
};
/*项目管理-详情页面-获取详情数据*/
module.exports.projectDetail = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await projectService.projectDetail(this, params.userId);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/*项目管理-详情页面-获取详情列表*/
module.exports.projectDetailList = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await projectService.projectDetailList(this, params.userId);
        let pageBean = new CustomPageBean(result);
        response.send(pageBean);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/*项目管理-详情页面-查看参数的页面*/
module.exports.projectParamPage = async function () {
    let response = new Response();
    response.render('back/operate/project/paramData');
    this.resolve(response);
};
/*项目管理-详情页面-获取参数数据*/
module.exports.projectParamData = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await projectService.projectParamData(this, params.userId);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/**
 * 项目管理-修改页面
 */
module.exports.projectUpdatePage = function () {
    let response = new Response();
    response.render('back/operate/project/project_update');
    this.resolve(response);
};
/*项目管理-修改页面-确认按钮*/
module.exports.projectUpdateSave = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await projectService.projectUpdateSave(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/*项目管理-修改页面-修改参数的页面*/
module.exports.paramUpdatePage = async function () {
  let response = new Response();
  response.render('back/operate/project/param_update');
  this.resolve(response);
}


/*/!*项目管理-详情页面-查看参数的页面*!/
module.exports.projectParamPage =  async function () {
  let response = new Response();
  response.render('back/operate/project/paramData');
  this.resolve(response);
};*/



/*项目管理-修改页面-修改参数的保存按钮*/
module.exports.paramUpdateSave = async function () {
  let req = this.req;
  let params = req.body;
  let response = new Response();
  try {
    let result = await projectService.paramUpdateSave(this, params);
    response.send(result);
  } catch (error) {
    logger.error(error);
  }
  this.resolve(response);
}
/**
 * 项目管理-删除按钮
 */
module.exports.projectDelete = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await projectService.projectDelete(this, params.userId);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};